package com.yishun.springboot.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.RequestGongWuShu.CWRService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yishun.springboot.mapper.GwsCWRMapper;
import com.yishun.springboot.mapper.RecordNumMapper;
import com.yishun.springboot.pojo.LayminiBaseInfoReturnBeans;
import com.yishun.springboot.pojo.GwsTeamType;
import com.yishun.springboot.pojo.UploadGWSAddTeam;

import lombok.extern.slf4j.Slf4j;

/**
 * 深圳工务署Service
 * 
 * @author XiaoHuang
 *
 */
@Service
@Slf4j
public class LayminiGWSService {

	// 记录成功提交到工务署的条数(记录类型：通用表通用类型)
	@Autowired
	RecordNumMapper recordNumMapper;

	@Autowired
	GwsCWRMapper cWRMapper;

	// 返回工种信息
	public JSONObject GetDictListJobName() {

		LayminiBaseInfoReturnBeans laymini = new LayminiBaseInfoReturnBeans();
		List<Map<String, Object>> l = cWRMapper.findAllDictListJobNameToMap();

		JSONArray data = JSONArray.parseArray(JSONArray.toJSON(l).toString());
		log.info("dataJson:" + data);

		laymini.setCode(0);
		laymini.setMsg("");
		laymini.setCount(1000);
		laymini.setData(data);
		String string = JSON.toJSONString(laymini);
		JSONObject results = JSON.parseObject(string);
		return results;
	}

	// 返回班组信息
	public JSONObject GetTeam_Type() {

		LayminiBaseInfoReturnBeans laymini = new LayminiBaseInfoReturnBeans();
		List<Map<String, Object>> l = cWRMapper.findAllTeamTypeToMap();

		JSONArray data = JSONArray.parseArray(JSONArray.toJSON(l).toString());

		laymini.setCode(0);
		laymini.setMsg("");
		laymini.setCount(1000);
		laymini.setData(data);
		String string = JSON.toJSONString(laymini);
		JSONObject results = JSON.parseObject(string);

		// layui格式需要在后台整理就违背了耦合分离的原则，故前后端分离项目一般来说应该不会出现在layui
		return results;
	}

	public JSONObject AddTeam(UploadGWSAddTeam d) {

		List<GwsTeamType> l = cWRMapper.findTeamTypeAll();
		String info = "";
		CWRService c = new CWRService();

		info = c.addTeam(d);
		JSONObject results = JSON.parseObject(info);
		return results;

	}

	/**
	 * 上传实名制图片信息接口
	 * 
	 * @param file
	 * @return
	 */
	public String UploadImage(MultipartFile file) {

		CWRService cWRServiceDemo = new CWRService();
		String a = cWRServiceDemo.UploadImage(file);
		log.info("files:" + file.getSize());

		return a;

		// {"result":"true","code":"00","status":"200","message":"成功","result_data":{"image_id":"8fc3c24d06b59e19fc211c3b5bf1113c"}}
	}

}
